######################################################
# CNOK project, Anyang Normal University, IMP-CAS
#
# CMakeLists.txt for user-composed programs
# Author: SUN Yazhou, asia.rabbit@163.com
# Created: 2020/07/08
# Last modified: 2022/12/06, SUN Yazhou
######################################################

cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)

project(MOMD)

# find_program(CLANG_EXECUTABLE clang++)
# find_program(GXX_EXECUTABLE g++)
# if(CLANG_EXECUTABLE)
#   set(CMAKE_CXX_COMPILER "clang++")
# elseif(GXX_EXECUTABLE)
#   set(CMAKE_CXX_COMPILER "g++")
# else()
#   message(FATAL_ERROR "No CXX compilers were found")
# endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
set(CMAKE_BUILD_TYPE "Release")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

# import OpenCV
option(USE_OpenCV "WHETHER TO USE OpenCV" OFF)
if(USE_OpenCV)
  # QUIET: do not issue a warning if the package is not found
  find_package(OpenCV QUIET) # to visualize nonzeros of large sparse matrix
endif()
if(OpenCV_FOUND)
  message(STATUS "found OpenCV")
  message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
  option(_OpenCV_ "OpenCV found" ON)
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# import ROOT
option(USE_ROOT "WHETHER TO USE ROOT" OFF)
if(USE_ROOT)
  # QUIET: do not issue a warning if the package is not found
  find_package(ROOT QUIET) # to use its TTree class for large sparse matrix
endif()
if(ROOT_FOUND)
  message(STATUS "found ROOT")
  message(STATUS "ROOT_DIR: ${ROOT_DIR}")
  option(_ROOT_ "ROOT found" ON)
  include_directories(${ROOT_INCLUDE_DIRS})
endif()

# swith option for catch2 -- a 3rd-party cpp unit-test package
option(CATCH_CNOK "CATCH2 TEST" OFF)

message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CATCH UNIT TEST: ${CATCH_CNOK}")

# copy the config files to the build directory
execute_process(COMMAND cp -r ${PROJECT_SOURCE_DIR}/config ${PROJECT_BINARY_DIR})
# copy ROOT macros for visualizations
aux_source_directory(vis VIS_SCRIPTS)
foreach(_script ${VIS_SCRIPTS})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${_script}
    ${PROJECT_BINARY_DIR}/${_script}
    COPYONLY
  )
endforeach()

add_subdirectory(cnok) # library path
add_subdirectory(fci) # library path
add_subdirectory(src) # user-defined source file path
